import logging

from Base.base import Base
from Page.mp.page_ele import PageElement


class MpPublicArticle(Base):

    def __init__(self):
        super().__init__("mp")
        logging.info("发表文章页面")

    def public_article(self, title, content, channel):
        """
        发表文章
        :param title: 文章标题
        :param content: 文章内容
        :param channel: 频道名字
        :return:
        """
        logging.info("输入完文章标题")
        # 输入文章标题
        self.input_ele(PageElement.mp_public_article_title_css, title)
        logging.info("切换到iframe")
        # 切换iframe
        self.driver.switch_to.frame(PageElement.mp_public_article_content_iframe_id)
        logging.info("输入文章内容")
        # 输入文章内容
        self.input_ele(PageElement.mp_public_article_content_id, content)
        # 切换回默认页面
        self.driver.switch_to.default_content()
        # 选择封面
        self.search_click(PageElement.mp_public_article_cover_xpath)
        # 选择频道
        self.select_option_name(PageElement.mp_public_article_select_btn_channel,
                                PageElement.mp_public_article_channel__all_name, channel)
        # 点击发表
        self.search_click(PageElement.mp_public_article_publish_btn)
